<%@ page import="org.json.simple.*"%> <%--json_simple_1-1.jar--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    import = "java.sql.*" %>

	<%
	request.setCharacterEncoding("UTF-8");
	
	String url = "jdbc:oracle:thin:@155.230.193.42:1521:oraknu";
	String user = "system";
	String pass = "DBLab012345";
	String id_u = (String)session.getAttribute("logID");
	Connection con = null;
	String sql = null;
	int result;
	
	JSONArray resultArray = new JSONArray();
	
	try
	{
		Class.forName("oracle.jdbc.driver.OracleDriver");
		System.out.println("success");
	}
	catch(ClassNotFoundException e)
	{
		System.err.println("error = " + e.getMessage());
		System.exit(1);
	}
	try
	{
		con = DriverManager.getConnection(url, user, pass);
	}
	catch(SQLException e)
	{
		System.err.println("sql error = " + e.getMessage());
		System.exit(1);
	}
	try
	{
		con.setAutoCommit(false);
		
		sql = "select bid, bname, btime, id_a from Bookmark  where id_u = ?";
		
		PreparedStatement pstmt = con.prepareStatement(sql);
		pstmt = con.prepareStatement(sql);
		pstmt.setString(1,id_u);
		
		ResultSet rs = pstmt.executeQuery();
		
		while(rs.next())
		{
			int bid = rs.getInt(1);
			String bname = rs.getString(2);
			String btime = rs.getString(3);
			int id_a = rs.getInt(4);
			
			JSONObject resultJson = new JSONObject();
							
			resultJson.put("b_id", bid);
			resultJson.put("b_name", bname);
			resultJson.put("b_time", btime);
			resultJson.put("b_id_a", id_a);
			resultArray.add(resultJson);
		}
		
		pstmt.close();
		con.close();	
	}
	catch(Exception e)
	{
		System.err.println("sql error = " + e.getMessage());
	}
	
	out.print(resultArray);
			
%>